package zzps.exeed.kernel.core;

import zzps.exeed.kernel.tool.ClassTool;

import java.util.List;
import java.util.function.Consumer;

public class ClassPathPandaEmbryoScanner extends ClassPathScanner {


    private Consumer<Class<?>> processor;

    public ClassPathPandaEmbryoScanner(ClassLoader classLoader) {
        super(classLoader);
        super.fileFilter = s -> s.endsWith(".class");
    }

    public void setProcessor(Consumer<Class<?>> processor) {
        this.processor = processor;
    }

    public void scan(String... basePackages) {
        List<String> classPathList = doScan(basePackages);
        for (String classpath : classPathList) {
            String className = classpath.substring(0,classpath.length() -6).replace('/', '.');
            Class<?> aClass = ClassTool.loadClass(className, classLoader);
            processor.accept(aClass);
        }

    }

}
